# coding: utf-8
# @Author: 莫小鱼
import configparser

from AutoWebTest.config.setting import FILE_PATH
from AutoWebTest.utils.log_util import logs


class ConfigParse:
    """
    解析.ini文件
    """
    def __init__(self,file_path=FILE_PATH['ini']):
        self.config = configparser.ConfigParser()
        self.file_path = file_path
        self.read_config()

    def read_config(self):
        self.config.read(self.file_path)

    def get_value(self,section,option):
        """
        获取配置文件的信息
        :param section: 头
        :param option:
        :return:
        """
        try:
            value = self.config.get(section,option)
            return value
        except Exception as e:
            logs.error(f"解析配置文件异常，原因：{e}")

    def get_host(self,option):
        return self.get_value('HOST',option)

    def get_section_mysql(self,option):
        return self.get_value('MYSQL',option)


# if __name__ == '__main__':
#     conf = ConfigParse()
#     print(conf.get_host('host'))
